package com.example.teamtribe.main.club.clubintroduce;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.example.teamtribe.R;
import com.example.teamtribe.utils.Utility;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class FileGridAdapter extends RecyclerView.Adapter<FileGridAdapter.ViewHolder> {

    private Context context;
    private List<String> fileNames = new ArrayList<>();

    public void add(String fileName) {
        fileNames.add(fileName);
    }

    public void addAll(Collection<String> fileNames) {
        this.fileNames.addAll(fileNames);
    }

    public void clear() {
        fileNames.clear();
    }

    @Override
    public FileGridAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        context = parent.getContext();
        View view = LayoutInflater.from(context).inflate(R.layout.item_club_photo, parent, false);
        final FileGridAdapter.ViewHolder holder = new FileGridAdapter.ViewHolder(view);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });
        return holder;
    }

    @Override
    public void onBindViewHolder(FileGridAdapter.ViewHolder holder, int position) {
        String fileName = fileNames.get(position);
        Glide.with(context).load(Utility.getUri(fileName)).into(holder.ivPhoto);
    }

    @Override
    public int getItemCount() {
        return fileNames.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        ImageView ivPhoto;

        public ViewHolder(View itemView) {
            super(itemView);
            ivPhoto = itemView.findViewById(R.id.iv_photo);
        }
    }
}
